package com.tjmc.finance.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.finance.service.UsageRecordsService;
import com.tjmc.recruit.common.core.constant.CommonConstants;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import com.tjmc.recruit.common.security.annotation.Inner;
import com.tjmc.recruit.finance.api.entity.UsageRecordsEntity;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 消费记录表
 *
 * @author recruit
 * @date 2024-11-25 14:17:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/usageRecords" )
@Tag(description = "usageRecords" , name = "消费记录表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class UsageRecordsController {

    private final UsageRecordsService usageRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param usageRecords 消费记录表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getUsageRecordsPage(@ParameterObject Page page, @ParameterObject UsageRecordsEntity usageRecords) {
        LambdaQueryWrapper<UsageRecordsEntity> wrapper = Wrappers.lambdaQuery(usageRecords);
        return R.ok(usageRecordsService.page(page, wrapper));
    }


    /**
     * 通过条件查询消费记录表
     * @param usageRecords 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject UsageRecordsEntity usageRecords) {
        return R.ok(usageRecordsService.list(Wrappers.query(usageRecords)));
    }

    /**
     * 新增消费记录表
     * @param usageRecords 消费记录表
     * @return R
     */
    @Operation(summary = "新增消费记录表" , description = "新增消费记录表" )
    @SysLog("新增消费记录表" )
    @PostMapping
    @Inner
    public R save(@RequestBody UsageRecordsEntity usageRecords) {
        R<Boolean> booleanR = usageRecordsService.addUsageRecords(usageRecords);
        if (booleanR.getCode() != CommonConstants.SUCCESS){
            return R.failed(booleanR.getMsg());
        }
        return R.ok();
    }
}
